<template>
  <div class="uni-tabs-content-croll">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" :label-width="$i18n.locale === 'en-US' ? '120px' : '120px'" class="uni-scroll">
      <el-divider content-position="left">公众号</el-divider>
      <el-row>
        <el-col :span="12">
          <el-form-item prop="mp.appId" :label="$t('wechat.appid')">
            <el-input v-model="dataForm.mp.appId" :placeholder="$t('wechat.appid')"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item prop="mp.appSecret" :label="$t('wechat.appsecret')">
            <el-input v-model="dataForm.mp.appSecret" :placeholder="$t('wechat.appsecret')"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item prop="mp.aesKey" :label="$t('wechat.aesKey')">
            <el-input v-model="dataForm.mp.aesKey" :placeholder="$t('wechat.aesKey')"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="mp.token" :label="$t('wechat.token')">
            <el-input v-model="dataForm.mp.token" :placeholder="$t('wechat.token')"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-divider content-position="left">小程序</el-divider>
      <el-row>
        <el-col :span="12">
          <el-form-item prop="ma.appId" :label="$t('wechat.appid')">
            <el-input v-model="dataForm.ma.appId" :placeholder="$t('wechat.appid')"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="ma.appSecret" :label="$t('wechat.appsecret')">
            <el-input v-model="dataForm.ma.appSecret" :placeholder="$t('wechat.appsecret')"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item prop="ma.aesKey" :label="$t('wechat.aesKey')">
            <el-input v-model="dataForm.ma.aesKey" :placeholder="$t('wechat.aesKey')"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="ma.token" :label="$t('wechat.token')">
            <el-input v-model="dataForm.ma.token" :placeholder="$t('wechat.token')"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="ma.msgDataFormat" label="消息格式">
            <el-radio v-model="dataForm.ma.msgDataFormat" label="JSON">JSON</el-radio>
            <el-radio v-model="dataForm.ma.msgDataFormat" label="XML">XML</el-radio>
            <!-- <el-input v-model="dataForm.ma.msgDataFormat" placeholder="消息格式"></el-input> -->
          </el-form-item>
        </el-col>
      </el-row>
      <el-divider content-position="left">其他</el-divider>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="待办列表路径" prop="configParam">
            <!--文本框-->
            <el-input v-model="dataForm.mpPagepath" placeholder="待办列表路径"></el-input>
            <br />
            <span class="form-item-explain">工作流消息跳转小程序路径</span>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <!-- <el-col :span="24" style="text-align:center">
      <el-button size="small" type="primary" @click="dataFormSubmitHandle()">{{ $t('save') }}</el-button>
    </el-col> -->
    <div class="uni-tab-form-bottom">
      <el-button size="small" type="primary" @click="dataFormSubmitHandle()">{{ $t('save') }}</el-button>
    </div>
  </div>
</template>

<script>
import debounce from 'lodash/debounce'
// import mainContent from '@/views/main-content'
// var content = mainContent
export default {
  data () {
    return {
      timestamp: this.$route.params.timestamp,
      loading: false,
      dataForm: {
        mp: {
          token: '',
          appId: '',
          appSecret: '',
          aesKey: ''
        },
        ma: {
          token: '',
          appId: '',
          appSecret: '',
          aesKey: '',
          msgDataFormat: 'JSON'
        },
        mpPagepath: ''
      }
    }
  },
  computed: {
    dataRule () {
      return {

      }
    }
  },
  created () {
    this.init()
  },
  methods: {
    init () {
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        this.getInfo()
      })
    },
    // 获取信息
    getInfo () {
      this.loading = true
      this.$http.get(`/sys/appConfig/wechat`).then(({ data: res }) => {
        this.loading = false
        if (res.code !== 0) {
          return false
        }
        this.dataForm.ma = {
          ...this.dataForm.ma,
          ...res.data.ma
        }
        this.dataForm.mp = {
          ...this.dataForm.mp,
          ...res.data.mp
        }
        this.dataForm.mpPagepath = res.data.mpPagepath
      }).catch(() => {
        this.loading = false
      })
    },
    // 表单提交
    dataFormSubmitHandle: debounce(function () {
      this.$refs['dataForm'].validate((valid) => {
        if (!valid) {
          return false
        }
        this.$http['post']('/sys/appConfig/wechat', this.dataForm).then(({ data: res }) => {
          if (res.code !== 0) {
            return false
          }
          this.$message({
            message: this.$t('prompt.success'),
            type: 'success',
            duration: 500,
            onClose: () => {
            }
          })
        }).catch(() => { })
      })
    }, 1000, { 'leading': true, 'trailing': false })
  }
}
</script>
<style scoped>
</style>
